{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "# `create_db_report()`: generate summary of your databases"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Overview\n",
    "\n",
    "The goal of `create_db_report` function is to present data from large databases in a comprehensive manner for easy interpretation of the users.\n",
    "\n",
    "1- Tables: summaries the structure of the tables including primary key and foreign key constraints\n",
    "2- Columns: Enlists columns from all database table along with properties of column fields\n",
    "3- Constraints: Identify foreign key constraints between tables\n",
    "\n",
    "Currently, `create_db_report` supports SQLite, PostgreSQL, and MySQL databases."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Creating SQLAlchemy `create_engine` object"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from dataprep.datasets import load_db\n",
    "db_engine = load_db('sakila.db')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Generate report via `create_db_report(database_engine)`\n",
    "\n",
    "Here we provide with an example using SQLite database to demonstrate the functionality:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "is_executing": true,
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from dataprep.eda import create_db_report\n",
    "report = create_db_report(db_engine)"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "The report is currently only supported in browser view"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "report.show_browser()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "The report can also be saved to local directory, if `path` is not specified, current working directory will be used"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "report.save(path=\"/Users/Documents\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"
  },
  "kernelspec": {
   "display_name": "Python 3.9.10 64-bit",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}